package top.deepdesigner.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.deepdesigner.pojo.DtsFootprint;
import top.deepdesigner.service.DtsFootprintService;

import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/21 星期三 22:30:20 <br/>
 */
@Service
public class DtsFootprintServiceImpl extends ServiceImpl<BaseMapper<DtsFootprint>, DtsFootprint> implements DtsFootprintService {
  @Override
  public Long getFootprintCount() {
    return this.count();
  }

  @Override
  public List<DtsFootprint> getFootprintList(Integer page, Integer limit, String sort, String order, Integer userId, Integer goodsId) {
    QueryWrapper<DtsFootprint> wrapper = new QueryWrapper<>();
    wrapper
        .eq(userId != null, "user_id", userId)
        .eq(goodsId != null, "goods_id", goodsId)
        .orderBy(true, "asc".equalsIgnoreCase(order), sort);
    Page<DtsFootprint> userPage = new Page<>(page, limit);
    return this.page(userPage, wrapper).getRecords();
  }
}